<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title></title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="robots" content="all,follow">
    <!-- Bootstrap CSS-->
    <link rel="stylesheet" href="static/vendor/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome CSS-->
    <link rel="stylesheet" href="static/vendor/font-awesome/css/font-awesome.min.css">
    <!-- Fontastic Custom icon font-->
    <link rel="stylesheet" href="static/css/fontastic.css">
    <!-- Google fonts - Poppins -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins:300,400,700">
    <!-- theme stylesheet-->
    <link rel="stylesheet" href="static/css/style.default.css" id="theme-stylesheet">
    <!-- Custom stylesheet - for your changes-->
    <link rel="stylesheet" href="static/css/custom.css">
    <!-- Favicon-->
    <link rel="shortcut icon" href="static/img/favicon.ico">
    <!-- Tweaks for older IEs-->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
        <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script><![endif]-->
    <style>
        .table tr td,
        .table tr th {
            flex: 1;
            text-align: center;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="page">
            <!-- Main Navbar-->
            <header class="header">
                <nav class="navbar">
                    <!-- Search Box-->
                    <div class="search-box">
                        <button class="dismiss"><i class="icon-close"></i></button>
                        <form id="searchForm" action="#" role="search">
                            <input type="search" placeholder="What are you looking for..." class="form-control">
                        </form>
                    </div>
                    <div class="container-fluid">
                        <div class="navbar-holder d-flex align-items-center justify-content-between">
                            <!-- Navbar Header-->
                            <div class="navbar-header">
                                <!-- Navbar Brand -->
                                <a href="index.html" class="navbar-brand d-none d-sm-inline-block">
                                    <div class="brand-text d-none d-lg-inline-block"><span>淘书斋后台管理</span></div>
                            </div>
                            <!-- Navbar Menu -->
                            <ul class="nav-menu list-unstyled d-flex flex-md-row align-items-md-center">
                                <!-- Search-->
                                <li class="nav-item d-flex align-items-center">
                                    <a href="#"></a>
                                </li>

                                <!-- Logout    -->
                                <li class="nav-item">
                                    <li @click="logout()">
                                        <a href="#" class="nav-link logout"> <span class="d-none d-sm-inline">退出</span><i class="fa fa-sign-out"></i></a>
                                    </li>
                                </li>
                            </ul>
                        </div>
                    </div>
                </nav>
            </header>
            <div class="page-content d-flex align-items-stretch">
                <!-- Side Navbar -->
                <nav class="side-navbar">
                    <!-- Sidebar Header-->
                    <div class="sidebar-header d-flex align-items-center">
                        <div class="avatar"><img src="static/img/gao.jpg" alt="..." class="img-fluid rounded-circle"></div>
                        <div class="title">
                            <h1 class="h4">{{adminName}}</h1>
                            <p>管理员</p>
                        </div>
                    </div>
                    <!-- Sidebar Navidation Menus--><span class="heading">管理</span>
                    <ul class="list-unstyled">
                        <li>
                            <a href="index.html"> <i class="icon-home"></i>首页</a>
                        </li>
                        <li class="active">
                            <a href="#bookDownDropdown" aria-expanded="false" data-toggle="collapse"> <i class="icon-interface-windows"></i>书本管理</a>
                            <ul id="bookDownDropdown" class="collapse list-unstyled ">
                                <li><a href="book.html">书本列表</a></li>
                                <li><a href="booktype.html">书本类型列表</a></li>
                            </ul>
                        </li>

                        <li>
                            <a href="#orderDownDropdown" aria-expanded="false" data-toggle="collapse"> <i class="icon-interface-windows"></i>订单管理</a>
                            <ul id="orderDownDropdown" class="collapse list-unstyled ">
                                <li><a href="order.html">订单列表</a></li>
                            </ul>
                        </li>

                        <li>
                            <a href="#userDownDropdown" aria-expanded="false" data-toggle="collapse"> <i class="icon-interface-windows"></i>用户管理</a>
                            <ul id="userDownDropdown" class="collapse list-unstyled ">
                                <li><a href="user.html">用户列表</a></li>

                            </ul>
                        </li>


                    </ul><span class="heading">设置</span>
                    <ul class="list-unstyled">
                        <li>
                            <a href="role.html"> <i class="icon-flask"></i>权限管理 </a>
                        </li>
                    </ul>
                </nav>
                <div class="content-inner">
                    <!-- Page Header-->
                    <header class="page-header">
                        <div class="container-fluid">
                            <h2 class="no-margin-bottom">淘书斋</h2>
                        </div>
                    </header>
                    <!-- Breadcrumb-->
                    <div class="breadcrumb-holder container-fluid">
                        <ul class="breadcrumb">
                            <li class="breadcrumb-item"><a href="index.html">首页</a></li>
                            <li class="breadcrumb-item active">书本类型管理 </li>
                        </ul>
                    </div>



                    <section class="tables">
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-lg-12">
                                    <div class="card" id="cardhtml">
                                        <div class="card-close">
                                            <div class="dropdown">
                                                <button type="button" id="closeCard1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="dropdown-toggle"><i class="fa fa-ellipsis-v"></i></button>
                                                <div aria-labelledby="closeCard1" class="dropdown-menu dropdown-menu-right has-shadow">
                                                    <a class="dropdown-item edit" @click="addPage()"> <i class="glyphicon glyphicon-plus"></i>添加书本类型</a>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="card-header d-flex align-items-center">
                                            <h3 class="h4">书本类型列表</h3>
                                        </div>


                                        <!-- <div class="card-body">

                                            <form class="form-inline">
                                                <div class="col-md-7"></div>
                                                <div class="form-group">
                                                    <select name="account" class="form-control" @change="selectChange($event)">
                                                        <option value="" selected="disabled" style="display:none">选择书本类型</option>
                                                        <option v-for="(item,index) in bookTypeList" :value="item.id">{{item.name}}</option>
                                                            </select>
                                                </div>
                                                &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;
                                                <div class="form-group">
                                                    <label for="inlineFormInputGroup" class="sr-only">Username</label>
                                                    <input v-model="condition" id="inlineFormInputGroup" type="text" placeholder="请输入编号或书名" class="mr-3 form-control">
                                                </div>
                                                <div class="form-group">
                                                    <button class="btn btn-primary" type="button" @click="findByCondition()">搜索</button>
                                                </div>
                                            </form>
                                        </div> -->

                                        <div class="card-body">

                                            <div class="table-responsive">
                                                <table class="table table-bordered table-striped">
                                                    <thead>
                                                        <tr>
                                                            <th>编号</th>
                                                            <th>名称</th>
                                                            <th>操作</th>

                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <tr v-for="(item,index) in bookTypeList">
                                                            <th scope="row">{{item.bookTypeId}}</th>
                                                            <td>{{item.typeName}}</td>

                                                            <td>
                                                                <!-- Standard button -->

                                                                <button type="button" class="btn btn-success btn-sm" data-toggle="modal" data-target="#updateModal" @click="updateModal(item)"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> 更新</button>
                                                                <button type="button" class="btn btn-danger btn-sm" data-toggle="modal" data-target="#deleteModal" @click="deleteModal(item.bookTypeId,item.typeName)"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span> 删除</button>

                                                            </td>

                                                        </tr>



                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>


                                        <form class="form-inline">
                                            <div class="col-md-7"></div>
                                            <div id="page_nav">
                                                <nav aria-label="Page navigation">
                                                    <ul class="pagination">
                                                        <li @click="firstPage()"><a>首页</a></li>

                                                        <li v-if="ifHasPrevious" @click="prePage()">
                                                            <a aria-label="Previous"> <span aria-hidden="true">&laquo;</span>
                                                            </a>
                                                        </li>

                                                        <li v-else class="disabled">
                                                            <a aria-label="Previous"> <span aria-hidden="true">&laquo;</span>
                                                            </a>
                                                        </li>
                                                        <template v-for="(item,index) in pageNums">
                                                        <li v-if="item==currentPage" class="active" @click="numPage(item, $event)"><a>{{item}}</a></li>
                                                        <li v-else @click="numPage(item, $event)"><a>{{item}}</a></li>
                                                    </template>
                                                        <li v-if="ifHasNext" @click="nextPage()">
                                                            <a aria-label="Next"> <span aria-hidden="true">&raquo;</span>
                                                            </a>
                                                        </li>

                                                        <li v-else class="disabled">
                                                            <a aria-label="Next"> <span aria-hidden="true">&raquo;</span>
                                                            </a>
                                                        </li>
                                                        <li @click="lastPage()"><a>尾页</a></li>
                                                    </ul>
                                                </nav>
                                            </div>
                                        </form>



                                    </div>


                                </div>


                            </div>
                    </section>





                    <!-- Page Footer-->
                    <footer class="main-footer">
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-6">
                                    <p class="weui-footer__text">Copyright © 2019 <a style="color:#3f8b81" href="#">抓娃小组</a>&nbsp版权所有</p>
                                </div>
                                <div class="col-sm-6 text-right">
                                    <p></p>
                                    <!-- Please do not remove the backlink to us unless you support further theme's development at https://bootstrapious.com/donate. It is part of the license conditions. Thank you for understanding :)-->
                                </div>
                            </div>
                        </div>
                    </footer>
                    </div>
                </div>
            </div>




            <!-- Modal-->
            <div id="updateModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" class="modal fade text-left">
                <div role="document" class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4 id="exampleModalLabel" class="modal-title">更新书本类型</h4>
                            <button type="button" data-dismiss="modal" aria-label="Close" class="close"><span aria-hidden="true">×</span></button>
                        </div>
                        <div class="modal-body">
                            <form>
                                <div v-if="typeNameValid==='0'" class="form-group row">
                                    &nbsp;&nbsp;<label class="form-control-label">名称</label>
                                    <div class="col-sm-6">
                                        <input v-model="bookType.typeName" type="text" placeholder="请输入名称" class="form-control" @change="typeNameChange()">
                                    </div>
                                </div>

                                <div v-else-if="typeNameValid==='1'" class="form-group row has-success">

                                    &nbsp;&nbsp;<label class="form-control-label">名称</label>
                                    <div class="col-sm-6">
                                        <input v-model="bookType.typeName" type="text" placeholder="请输入名称" class="form-control is-valid" @change="typeNameChange()">
                                    </div>
                                </div>

                                <div v-else class="form-group row has-danger">

                                    &nbsp;&nbsp;<label class="form-control-label">名称</label>
                                    <div class="col-sm-6">
                                        <input v-model="bookType.typeName" type="text" placeholder="请输入名称" class="form-control is-invalid" @change="typeNameChange()">
                                        <div class="invalid-feedback">请输入名称</div>
                                    </div>
                                </div>

                            </form>

                        </div>
                        <div class="modal-footer">
                            <button type="button" data-dismiss="modal" class="btn btn-secondary">取消</button>
                            <button type="button" class="btn btn-primary" @click="updatebookType()">确认</button>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Modal-->
            <div id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" class="modal fade text-left">
                <div role="document" class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4 id="exampleModalLabel" class="modal-title">确认删除该书本类型？</h4>
                            <button type="button" data-dismiss="modal" aria-label="Close" class="close"><span aria-hidden="true">×</span></button>
                        </div>
                        <div class="modal-body">

                            <p>编号：{{deletebookTypeId}}</p>
                            <p>书名：{{deletebookTypeName}}</p>


                        </div>
                        <div class="modal-footer">
                            <button type="button" data-dismiss="modal" class="btn btn-secondary">取消</button>
                            <button type="button" class="btn btn-primary" @click="deletebookType()">确认</button>
                        </div>
                    </div>
                </div>
            </div>



            <!-- JavaScript files-->
            <script src="static/vendor/jquery/jquery.min.js"></script>
            <script src="static/vendor/popper.js/umd/popper.min.js">
            </script>
            <script src="static/vendor/bootstrap/js/bootstrap.min.js"></script>
            <script src="static/vendor/jquery.cookie/jquery.cookie.js">
            </script>
            <script src="static/vendor/chart.js/Chart.min.js"></script>
            <script src="static/vendor/jquery-validation/jquery.validate.min.js"></script>
            <script src="static/js/charts-home.js"></script>
            <!-- Main File-->
            <script src="static/js/front.js"></script>
            <script src="static/node_modules/vue/dist/vue.js"></script>

            <script>
                var vm = new Vue({
                    el: '#app',
                    data: {
                        adminName: '',
                        pageNums: [],
                        currentPage: 0,
                        pageCount: 0,
                        ifHasPrevious: false,
                        ifHasNext: true,
                        msg: 'hello',
                        bookTypeList: [],
                        //服务器:http://47.100.136.219
                        serverIp: 'http://47.100.136.219',
                        ifLocal: false,
                        bookTypeId: 0,
                        condition: '',
                        deletebookTypeName: '',
                        deletebookTypeId: '',
                        typeNameValid: '0',
                        bookType: {
                            typeName: ''
                        },



                    },
                    mounted() {

                        let _this = this;
                        if (this.ifLocal) {
                            this.serverIp = "http://localhost";
                        }


                        $.ajax({
                            type: "GET",
                            url: _this.serverIp + ":8088/boot/admincommon/info",
                            success: function(response) {
                                if (response.code == 200) {
                                    console.log(response.data);
                                    _this.adminName = response.data.data.principal.username
                                }
                            },

                        });


                        _this.currentPage = 1;

                        $.ajax({
                            type: "GET",
                            url: _this.serverIp + ":8088/boot/adminbook/booktype/?pageIndex=" + _this.currentPage,
                            success: function(response) {
                                if (response.code == 200) {
                                    console.log(response.data);
                                    console.log(response.data.bookType.list);
                                    _this.bookTypeList = response.data.bookType.list;
                                    _this.pageNums = response.data.bookType.navigatepageNums;
                                    _this.pageCount = response.data.bookType.pages;

                                }
                            },
                            error: function(response) {

                                $("#cardhtml").replaceWith('<div class="card-close"></div><div class="card-header d-flex align-items-center"><h3 class="h4">不好意思，您不是书本管理员，无权访问</h3></div>');


                            }
                        });
                    },
                    methods: {
                        logout() {
                            let _this = this;
                            $.ajax({
                                url: _this.serverIp + ':8088/boot/logout',
                                type: 'POST',
                                success: function(res, status) {
                                    console.log(res);
                                    location.href = "login.html";

                                },
                                error: function(res, status) {
                                    console.log(res);
                                }
                            });
                        },

                        addPage() {
                            location.href =
                                "booktype-add.html";
                        },

                        updateModal(item) {
                            this.bookType = item;
                        },
                        updatebookType() {
                            console.log(this.bookTypeId);
                            if (this.typeNameValid != "1") {
                                alert("请填写类型!");
                                return;
                            }

                            let _this = this;
                            $.ajax({
                                type: "PUT",
                                url: _this.serverIp + ":8088/boot/adminbook/booktype",
                                data: JSON.stringify(_this.bookType), //必要
                                dataType: "json",
                                contentType: "application/json",
                                success: function(response) {
                                    if (response.code == 200) {
                                        console.log(response.data);
                                        $('#updateModal').modal('hide');

                                        $.ajax({
                                            type: "GET",
                                            url: _this.serverIp + ":8088/boot/adminbook/booktype/?pageIndex=" + _this.currentPage,
                                            success: function(response2) {
                                                if (response2.code == 200) {
                                                    console.log(response2.data);
                                                    console.log(response2.data.bookType.list);
                                                    _this.bookTypeList = response2.data.bookType.list;
                                                    _this.pageNums = response2.data.bookType.navigatepageNums;
                                                    _this.pageCount = response2.data.bookType.pages;

                                                }
                                            }
                                        });
                                    }
                                },
                            });

                        },

                        deleteModal(id, name) {

                            this.deletebookTypeId = id;
                            this.deletebookTypeName = name;
                        },

                        deletebookType() {
                            console.log(this.deletebookTypeId);

                            let _this = this;
                            $.ajax({
                                type: "DELETE",
                                url: _this.serverIp + ":8088/boot/adminbook/booktype/" + _this.deletebookTypeId,
                                success: function(response) {
                                    if (response.code == 200) {
                                        console.log(response.data);
                                        $('#deleteModal').modal('hide');

                                        $.ajax({
                                            type: "GET",
                                            url: _this.serverIp + ":8088/boot/adminbook/booktype/?pageIndex=" + _this.currentPage,
                                            success: function(response2) {
                                                if (response2.code == 200) {
                                                    console.log(response2.data);
                                                    console.log(response2.data.bookType.list);
                                                    _this.bookTypeList = response2.data.bookType.list;
                                                    _this.pageNums = response2.data.bookType.navigatepageNums;
                                                    _this.pageCount = response2.data.bookType.pages;

                                                }
                                            }
                                        });
                                    }
                                },
                            });

                        },
                        selectChange(e) {
                            console.log(e.target.value) // 选择项的value

                            this.bookTypeId = e.target.value;


                        },



                        prePage() {
                            let _this = this;
                            _this.currentPage = _this.currentPage - 1;

                            $.ajax({
                                type: "GET",
                                url: _this.serverIp + ":8088/boot/adminbook/booktype/?pageIndex=" + _this.currentPage,
                                success: function(response) {
                                    if (response.code == 200) {
                                        console.log(response.data);
                                        console.log(response.data.bookType.list);
                                        _this.bookTypeList = response.data.bookType.list;
                                        _this.pageNums = response.data.bookType.navigatepageNums;
                                        _this.pages = response.data.bookType.pages;
                                        _this.ifHasPrevious = response.data.bookType.hasPreviousPage;
                                        _this.ifHasNext = response.data.bookType.hasNextPage;
                                    }
                                }
                            });
                        },
                        nextPage() {
                            let _this = this;
                            _this.currentPage = _this.currentPage + 1;

                            $.ajax({
                                type: "GET",
                                url: _this.serverIp + ":8088/boot/adminbook/booktype/?pageIndex=" + _this.currentPage,
                                success: function(response) {
                                    if (response.code == 200) {
                                        console.log(response.data);
                                        console.log(response.data.bookType.list);
                                        _this.bookTypeList = response.data.bookType.list;
                                        _this.pageNums = response.data.bookType.navigatepageNums;
                                        _this.pages = response.data.bookType.pages;
                                        _this.ifHasPrevious = response.data.bookType.hasPreviousPage;
                                        _this.ifHasNext = response.data.bookType.hasNextPage;
                                    }
                                }
                            });
                        },

                        firstPage() {
                            let _this = this;
                            _this.currentPage = 1;

                            $.ajax({
                                type: "GET",
                                url: _this.serverIp + ":8088/boot/adminbook/booktype/?pageIndex=" + _this.currentPage,
                                success: function(response) {
                                    if (response.code == 200) {
                                        console.log(response.data);
                                        console.log(response.data.bookType.list);
                                        _this.bookTypeList = response.data.bookType.list;
                                        _this.pageNums = response.data.bookType.navigatepageNums;
                                        _this.pages = response.data.bookType.pages;
                                        _this.ifHasPrevious = response.data.bookType.hasPreviousPage;
                                        _this.ifHasNext = response.data.bookType.hasNextPage;
                                    }
                                }
                            });
                        },
                        lastPage() {
                            let _this = this;
                            _this.currentPage = _this.pageCount;

                            $.ajax({
                                type: "GET",
                                url: _this.serverIp + ":8088/boot/adminbook/booktype/?pageIndex=" + _this.currentPage,
                                success: function(response) {
                                    if (response.code == 200) {
                                        console.log(response.data);
                                        console.log(response.data.bookType.list);
                                        _this.bookTypeList = response.data.bookType.list;
                                        _this.pageNums = response.data.bookType.navigatepageNums;
                                        _this.pages = response.data.bookType.pages;
                                        _this.ifHasPrevious = response.data.bookType.hasPreviousPage;
                                        _this.ifHasNext = response.data.bookType.hasNextPage;
                                    }
                                }
                            });
                        },



                        numPage: function(num, event) {
                            if (this.curpage == num) {
                                return;
                            }
                            let _this = this;
                            _this.currentPage = num;

                            $.ajax({
                                type: "GET",
                                url: _this.serverIp + ":8088/boot/adminbook/booktype/?pageIndex=" + _this.currentPage,
                                success: function(response) {
                                    if (response.code == 200) {
                                        console.log(response.data);
                                        console.log(response.data.bookType.list);
                                        _this.bookTypeList = response.data.bookType.list;
                                        _this.pageNums = response.data.bookType.navigatepageNums;
                                        _this.pages = response.data.bookType.pages;
                                        _this.ifHasPrevious = response.data.bookType.hasPreviousPage;
                                        _this.ifHasNext = response.data.bookType.hasNextPage;

                                    }
                                }
                            });


                        },
                        typeNameChange() {
                            let _this = this;

                            if (_this.bookType.typeName == "") {
                                _this.typeNameValid = "-1";
                            } else {
                                _this.typeNameValid = "1";
                            }
                        },


                    },
                });
            </script>
            </script>
</body>

</html